package com.maotaiapp.main;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.maotai.dao.QiangGouDao;
import com.maotai.util.IPFactory;
import com.maotaiapp.thread.MaoTaiAppDeleteInvoiceThread;

public class MaoTaiAppDeleteInvoice {

	public static void main(String[] args) {
		QiangGouDao qgs = new QiangGouDao();
		Connection c = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			c = DriverManager
					.getConnection("jdbc:mysql://localhost:3306/maotai?user=root&password=123456&useUnicode=true&characterEncoding=utf8");
			System.out.println("Opened database successfully");
//			while(true){
			// 获取账号
			List<Map<String, Object>> list = qgs.getAllMaotaiAppInvoice(c);
			
			if (list != null && list.size() > 0) {
				int count = list.size();
				JSONArray jArray = IPFactory.getIpAndPort();
				int countData = jArray.size();
				if (countData < count) {
					count = countData;
				}
				// 计算viewstates
				for (int i = 0; i < count; i++) {
					
					Map<String, Object> mapList = list.get(i);
					
					JSONObject jj = (JSONObject) jArray.get(i);
					
					MaoTaiAppDeleteInvoiceThread th = new MaoTaiAppDeleteInvoiceThread(mapList, jj);
					th.start();
				}
			}
//			else{
//				break;
//			}
//			}
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (c != null)
				try {
					c.close();
					System.out.println("close database successfully");
				} catch (SQLException e) {
				}
		}

	}
	
}
